package com.wy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/12/1714:30
 */
@RequestMapping("role")
@RestController
@RefreshScope
public class RoleController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("getAll1")
    public ResponseEntity<String> getAll1(){
        ResponseEntity<String> forEntity = restTemplate.getForEntity("http://wthrcdn.etouch.cn/weather_mini?city=沈阳", String.class);
        return forEntity;
    }

    @GetMapping("getHj")
    public Map<String,Object> getHj(){
        Map<String,Object> map = restTemplate.getForObject("http://my-user/shop/getHj", Map.class);
        return map;
    }
    @PostMapping("getAll")
    public List<Shop> getAll(){
        //List<Shop> list = restTemplate.getForObject("http://localhost:8081/shop/getAll", List.class);
        Shop shop = new Shop();
        shop.setName("12");
        List<Shop> list = restTemplate.postForObject("http://my-user/shop/pageList2",shop,List.class);
        return list;
    }
    @PostMapping("getAll2")
    public ResponseEntity getAll2(){
        Shop shop = new Shop();
        shop.setName("12");
        ResponseEntity<List> responseEntity = restTemplate.postForEntity("http://my-user/shop/pageList2", shop,List.class);
        List<Shop> list = responseEntity.getBody();
        System.out.println(list.toString());
        return responseEntity;
    }
}
